/**
 * Created by Luji on 2017/03/27.
 */
class Creat {
    constructor(edit , $modalInstance , userSrv) {
        "ngInject";
        this._modalInstance = $modalInstance;
        this._userSrv  = userSrv;
        this.params = {};
        if(edit){
            this.edit = true;
        }
    }
    cancel() {
        this._modalInstance.dismiss('cancel');
    }
    save(){
        this._userSrv.addUser(this.params).then(data=> {
            this._modalInstance.close();
            this._notification.error('新建用户成功.');
        }).catch(()=> {
            this._notification.error('新建用户有误.');
        });
    }
    checkUserCode(){
        if (this.params.userCode) {
            this.userCodeChecking = true;
            this._userSrv.checkUserCode(this.params.userCode).then(data=> {
                this.userForm.userCode.$setValidity('duplicate',!data);
                this.userForm.userCode.$setValidity('network',true);
            }).catch(data=> {
                this.userForm.userCode.$setValidity('network',false);
            }).finally(()=>{
                this.userCodeChecking = false;
            });
        }
    }
}
export default Creat